<template>
<!--  物料申请表 -->
  <div id="adduser">
    <el-dialog :title="datas.account?'修改申请':'物料申请'" :visible.sync="dialogVisible" width="40%" top="3vh" :close-on-click-modal='true'>
      <div style="width:90%;margin: 0 auto;padding-bottom:0px;" v-loading="loading">
        <decla :act="1"></decla>
        <div style="margin-top:10px;" class="tabbox">
          <p>物品名称：</p><a class="man">{{numdata.name}}</a>
        </div>
        <div style="margin-top:10px;" class="tabbox">
          <p>物品类型：</p><a class="man">{{id_name(numdata.typeId,$store.state.user.leidata)}}</a>
        </div>
        <div style="margin-top:10px;" class="tabbox">
          <p>型号：</p><a class="man">{{numdata.model}}</a>
        </div>
        <div style="margin-top:10px;" class="tabbox">
          <p>尺寸：</p><a class="man">{{numdata.size}}</a>
        </div>
        <div style="margin-top:10px;" class="tabbox">
          <p>供应商：</p><a class="man">{{numdata.provider}}</a>
        </div>
        <div style="margin-top:10px;" class="tabbox">
          <p>库存数量：</p><a class="man">{{numdata.amount}}</a>
        </div>
        <div style="margin-top:10px;" class="tabbox">
         <p>单价：</p><a class="man">{{numdata.price}}</a>
        </div>
        <div style="margin-top:10px;" class="tabbox">
          <p>物品编码：</p><a class="man">{{numdata.sku}}</a>
        </div>
        <div style="margin-top:10px;height:50px" class="tabbox">
          <p>备注：</p><a class="man">{{numdata.remarks}}</a>
        </div>
        <div style="margin-top:10px;" class="tabbox">
            <p>申请数量:</p>
            <el-input style='width:80%;' type="number" placeholder="请输入" v-model="datas.amount" clearable></el-input>
        </div>
        <div style="margin-top:10px;height:120px" class="tabbox">
          <p>申请原因:</p>
          <el-input type="textarea" style='width:80%;'
            :autosize="{ minRows: 4, maxRows: 4}"
            placeholder="请输入内容"
            v-model="datas.purpose" clearable>
          </el-input>
        </div>
      </div>
      <div style="width:100%;height:40px;margin-top:20px;">
        <div style="width:170px;margin: 0 auto;">
          <el-button type="danger" @click="Negate()" >取 消</el-button>
          <el-button type="primary" @click="gitact" style='float:right;'>确 定</el-button>
        </div>
      </div>
    </el-dialog>

  </div>
</template>
<script>
  import decla from '@/components/MES/steps/decla.vue'
  import { create } from '@/api_bast/decla_man.js'
  export default {
    name: 'decla_shen',
    components:{decla},
    computed:{},
    data() {
      return {
        loading:false,
        dialogVisible:false,
        datas:{
          goodsSku:'',//   要申请的物料sku
          createdBy:'',//       创建人的id，对应user表中的id
          createdTime:'',//    创建时间
          amount:'',//          申请数量
          purpose:'',//        申请原因
          price:'',//         单价
        },
        numdata:{},//物料信息
      }
    },
    props:{
      edit:Number
    },
    methods: {
      panertfn(item,numdata){
        (this.edit==1)?this.datas = item:this.qin();
        this.numdata = numdata;
        this.Negate();
      },
      Negate(){this.dialogVisible = !this.dialogVisible},//显隐取反
      qin(){//清除数据方法
        this.datas = {
          goodsSku:'',//   要申请的物料sku
          createdBy:'',//       创建人的id，对应user表中的id
          createdTime:'',//    创建时间
          amount:'',//          申请数量
          purpose:'',//        申请原因
          price:'',//         单价
        }
      },
      gitact(){//提交数据
        if(this.isNull(this.datas.amount)){this.$message({message: '请输入 申请数量',type: 'error'});return false}
        if(this.datas.amount<=0){this.$message({message: '申请数量必须大于零',type: 'error'});return false}
        if(this.datas.amount>this.numdata.amount){this.$message({message: '数量不足',type: 'error'});return false}
        if(this.isNull(this.datas.purpose)){this.$message({message: '请输入 申请原因',type: 'error'});return false}
        this.datas.goodsSku = this.numdata.sku;
        this.datas.price = this.numdata.price;
        this.datas.createdBy = this.json_object(this.resData()).id;
        this.loading=true;
        create(this.edit,this.datas).then(response => {
          this.loading = false;
          if(response.code==200){
            this.qin();
            this.$notify.success({title: '请求已提交',message: response.message});
            this.Negate();
          }
        })
      },
    },
    mounted() {
      // this.$parent.qin();//调用父组件方法
    }
  }
</script>

<style scoped>
  .man{
    height: 100%;
    padding: 5px 10px;
    border-radius:3px;
    border: 1px solid #DCDFE6;
  }
  /*.min{*/
  /*  font-weight: bold;*/
  /*}*/
  .sp1{
    /*width:10%;*/
    /*text-align:right;*/
    float: left;
  }
  .sp2{
    float: right;
  }
  .tabbox{
    width:100%;
    height:40px;
    line-height: 30px;
    margin-top:23px;
  }
  .tabbox p{
    font-size:14px;
    font-weight: bold;
    /*color:#000000;*/
    width:90px;
    text-align:right;
    margin-right:10px;
    float:left;
    overflow: hidden;
    text-overflow:ellipsis;
    white-space: nowrap;
    font-family:Source Han Sans CN;
  }
</style>
